<template>
	<view class="content">
		<h2 style="text-align: center;margin-bottom:30rpx;padding-top: 70rpx;color: white;">中国互联网络信息中心</h2>
		<view class="loginBox">

			<h3 style="text-align: center;margin-bottom:30rpx;color: white;">会议室预约系统</h3>


			<view class="inputBox">

				<uv-input color="white" customStyle="margin-bottom:40rpx;" prefixIcon="account-fill"
					prefixIconStyle="color:white;margin-left:20rpx;margin-right:20rpx;" shape="circle"
					placeholder="请输入用户名" border="surround" v-model="passport">

				</uv-input>
				<uv-input :password="true" color="white" prefixIcon="lock-fill"
					prefixIconStyle="color:white;margin-left:20rpx;margin-right:20rpx;" shape="circle"
					placeholder="请输入密码" border="surround" v-model="password">

				</uv-input>

				<button type="primary" @click="login" style="background-color: white; color: #3087fa;">登录</button>

			</view>
			<view class="tipbox">
				<view class="txt">

				</view>

			</view>
		</view>

	</view>
</template>

<script>
	import util from '../../api/util';
	import axios from 'axios';
	export default {

		data() {
			return {
				passport: '',
				password: '',
				rememberMe: false
			};
		},
		methods: {
			async login() {
				console.log(this.passport, this.password);
				const baseUrl = util.domain;
				console.log(baseUrl);
				uni.request({
					url: baseUrl + 'api/account/login',
					method: "GET",
					data: {
						passport: this.passport,
						password: this.password,
						rememberMe: this.rememberMe
					},
					success: (res) => {
						console.log(res, this.password)
						if (res.data.code === 200) {
							// 登录验证成功，保存用户身份信息到本地存储
							uni.setStorageSync('passport', this.passport);
							uni.setStorageSync('isLogin', true);
							// console.log(res.data.data.roleId);
							uni.setStorageSync('roleId', res.data.data.roleId);
							// 获取并存储 Cookie
							uni.setStorageSync('token', res.data.data.token);
							uni.setStorageSync('id', res.data.data.id);
							uni.getStorage({
								key: 'cookie',
								success: (res) => {
									console.log('获取到的cookie:', res);
								}
							})
							uni.getStorage({
								key: 'passport',
								success: (res) => {
									// console.log('获取到的passport:', res.data);
								}
							})
							if (this.password == 123456) {
								console.log("密码太简单");
								uni.navigateTo({
									url: './changePassword',
								});
							} else {
								uni.getStorage({
									key: 'roleId',
									success: (res) => {
										console.log('获取当前的roleId', res.data);
										uni.switchTab({
											url: '../../pages/app/metting/allMeeting'
										})
										// if (res.data == 1) {
										//   uni.switchTab({
										//     url: "../app/metting/myMeetings"
										//    });
										// } else{
										//   uni.switchTab({
										//     url: "../app/metting/myMeeting"
										//    });
										// }
									}
								})
							}
						} else {
							// 登录验证失败，提示错误信息
							uni.showToast({
								title: '用户名或密码错误',
								icon: 'none'
							});
						}
					}
				});
			}

		}
	}
</script>

<style lang="scss">
	.content {
		width: 750rpx;
		min-height: 1600rpx;
		background-image: url("../../static/images/login.jpg");
		background-size: 100% 100%;

	}

	svg {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 40%;
		box-sizing: border-box;
		display: block;
		background-color: #ffffff;
	}

	.loginBox {
		// background-color: blue;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -60%);
		width: 90%;
		border-radius: 20rpx;
		padding: 60rpx;
		box-sizing: border-box;
	}

	h3 {
		color: rgb(66, 157, 250);
		font-size: 40rpx;
		letter-spacing: 10rpx;
		margin-bottom: 40rpx;
	}

	.inputBox {}

	.ipt {
		height: 86rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		margin-bottom: 40rpx;
		background-color: #f5f5f5;
		border-radius: 10rpx;
		padding-left: 10rpx;
	}

	.ipt input {
		margin-left: 20rpx;
		font-size: 28rpx;
	}

	.ipt input {
		margin-left: 20rpx;
	}

	.forgetPwd {
		margin-top: 30rpx;
		font-size: 26rpx;
		color: #b5b5b5;
		text-align: end;
		padding: 0 10rpx;
		display: flex;
		justify-content: space-between;
	}

	button {
		margin-top: 20rpx;
		line-height: 85rpx;
		text-align: center;
		background: rgb(66, 157, 250);
		border-radius: 40rpx;
		color: #fff;
		margin-top: 40rpx;
	}

	.tip {
		text-align: center;
		font-size: 28rpx;
		position: fixed;
		bottom: 50rpx;
		left: 50%;
		transform: translate(-50%, -50%);
		color: #f4f4f4;
	}

	.tipbox {
		text-align: center;
		margin-top: 100rpx;
	}

	.otherUser {
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
	}

	.txt {
		font-size: 28rpx;
		color: #cbcbcb;
	}

	.otherUser .uni-icons {
		margin-left: 20rpx;
	}

	.yzm {
		text-align: end;
		font-size: 24rpx;
		background: linear-gradient(to right, rgb(66, 157, 250), rgb(0, 170, 127));
		height: 60rpx;
		width: 150rpx;
		line-height: 60rpx;
		text-align: center;
		border-radius: 10rpx;
		color: #fff;
	}
</style>